from django.http import *
from suds.client import Client
from django.template.loader import render_to_string
from app.luca_admin.models import Setting

clientNo = Setting.objects.get(name="user").setting
clientPass= Setting.objects.get(name="password").setting 
serviceType = Setting.objects.get(name="service_type").setting
senderName = Setting.objects.get(name="sender_name").setting

def smsClientData():
    clientNo = Setting.objects.get(name="user").setting
    clientPass= Setting.objects.get(name="password").setting
    serviceType = Setting.objects.get(name="service_type").setting
    senderName = Setting.objects.get(name="sender_name").setting
    data={'clientNo':clientNo,'clientPass':clientPass,'serviceType':serviceType,'senderName':senderName}
    return data

def smsClient():
    client = Client("http://center.fibosms.com/Service.asmx?WSDL")
    return client

def smsAbout():
    result = smsClient().service.About()
    return HttpResponse(result)

def smsCheckClient():
    result = smsClient().service.CheckClient(clientNo=smsClientData().get('clientNo'), clientPass=smsClientData().get('clientPass'))
    return HttpResponse(result)

def smsGetClientBalance():
    result = smsClient().service.GetClientBalance(clientNo=smsClientData().get('clientNo'), clientPass=smsClientData().get('clientPass'),serviceType=smsClientData().get('serviceType'))
    return HttpResponse(result)


def smsGetListSMSHostingWithBalance():
    result = smsClient().service.GetListSMSHostingWithBalance(clientNo=smsClientData().get('clientNo'), clientPass=smsClientData().get('clientPass'))
    return HttpResponse(result)

def smsGetClientSenderNameList():
    result = smsClient().service.GetClientSenderNameList(clientNo=smsClientData().get('clientNo'), clientPass=smsClientData().get('clientPass'))
    return HttpResponse(result)


def smsSendMaskedSMS(phoneNumber,smsMessage):
    result = smsClient().service.SendMaskedSMS(clientNo=smsClientData().get('clientNo'), clientPass=smsClientData().get('clientPass'),senderName=smsClientData().get('senderName'),phoneNumber=phoneNumber,smsMessage=smsMessage,smsGUID='',serviceType=smsClientData().get('serviceType'))
    return HttpResponse(result)

def smsGetClientSMSListOfPage(fromdate,todate,status,page):
    result = smsClient().service.GetClientSMSListOfPage(clientNo=smsClientData().get('clientNo'), clientPass=smsClientData().get('clientPass'),pageNO=page,fromDate=fromdate,toDate=todate,smsStatus=status,key='',serviceTypeID=smsClientData().get('serviceType'))
    return HttpResponse(result)

def GetTotalPageOfClientSMS(fromdate,todate,status):
    result = smsClient().service.GetTotalPageOfClientSMS(clientNo=smsClientData().get('clientNo'), clientPass=smsClientData().get('clientPass'),fromDate=fromdate,toDate=todate,smsStatus=status,key='',serviceTypeID=smsClientData().get('serviceType'))
    return result

